#include <sys/types.h>
#include <sys/stat.h>
#include <linux/input.h>
#include <fcntl.h>
#include <unistd.h>

#include <stdio.h>

int main(int argc,char *argv[])
{
	int fd = -1;
	struct input_event evt;
	if(argc < 2)
	{
		printf("Argument is too few\n");
		return 1;
	}

	/*open*/
	fd = open(argv[1],O_RDONLY);
	if(fd < 0)
	{
		printf("open %s failed\n",argv[1]);
		return 2;
	}

	/*init mpu6050*/

	while(1)
	{
		read(fd,&evt,sizeof(evt));
		if(evt.type == EV_ABS)
		{
			switch(evt.code)
			{
				case ABS_X:
					printf("Accel-x:%d\n",evt.value);
					break;
				case ABS_Y:
					printf("Accel-y:%d\n",evt.value);
					break;
				case ABS_Z:
					printf("Accel-z:%d\n",evt.value);
					break;
				case ABS_RX:
					printf("Gyro-x:%d\n",evt.value);
					break;
				case ABS_RY:
					printf("Gyro-y:%d\n",evt.value);
					break;
				case ABS_RZ:
					printf("Gyro-z:%d\n",evt.value);
					break;
				case ABS_MISC:
					printf("Temp:%d\n",evt.value);
					break;
			}
		}
	}


	/*close*/
	close(fd);
	fd = -1;
	return 0;
}
